package android.FiltrosJava;

public class LinearTransparency extends TransparencyMask{		
	protected boolean directionVertical = true;
	public LinearTransparency(){
		super(1.0f,0.0f,0,0,0);
	}
	
	public void setHorizontalTransparency(){
		directionVertical = false;		
	}
	
	public void setVerticalTransparency(){
		directionVertical = true;		
	}
			
	public float[][] computeMask(int dimX, int dimY){
		double interval;		
		if (directionVertical){
			interval = (maxT - minT)/ dimY;
			if (interval > 0)
				return maskVerticalIncrease(dimX, dimY, interval);
			else
				return maskVerticalDecrease(dimX, dimY, interval);
		}
		else{
			interval = (maxT - minT)/ dimX;
			if (interval > 0)
				return maskHorizontalIncrease(dimX, dimY, interval);
			else
				return maskHorizontalDecrease(dimX, dimY, interval);
		}		
	}
	
	protected float[][] maskVerticalIncrease(int dimX, int dimY, double interval){
		float[][] mask = new float[dimY][dimX];
		double transparency = minT;
		
		for ( int y = 0; y < dimY; y++ ) {
    		for ( int x = 0; x < dimX; x++ ) {
    			mask[y][x] = (float)(transparency);
    		}    		
    		transparency += interval;
    		if (transparency > maxT)
    			transparency = maxT;    		    		
		}		
		return mask;
	}
	
	protected float[][] maskHorizontalIncrease(int dimX, int dimY, double interval){
		float[][] mask = new float[dimY][dimX];
		double transparency = minT;
		
		for ( int x = 0; x < dimX; x++ ) {
    		for ( int y = 0; y < dimY; y++ ) {
    			mask[y][x] = (float)(transparency);
    		}    		
    		transparency += interval;
    		if (transparency > maxT)
    			transparency = maxT;    		    		
		}		
		return mask;
	}
	
	protected float[][] maskVerticalDecrease(int dimX, int dimY, double interval){
		float[][] mask = new float[dimY][dimX];
		double transparency = minT;
		
		for ( int y = 0; y < dimY; y++ ) {
    		for ( int x = 0; x < dimX; x++ ) {
    			mask[y][x] = (float)(transparency);
    		}    		
    		transparency += interval;
    		if (transparency < maxT)
    			transparency = maxT;    		    		
		}		
		return mask;
	}
	
	protected float[][] maskHorizontalDecrease(int dimX, int dimY, double interval){
		float[][] mask = new float[dimY][dimX];
		double transparency = minT;
		
		for ( int x = 0; x < dimX; x++ ) {
    		for ( int y = 0; y < dimY; y++ ) {
    			mask[y][x] = (float)(transparency);
    		}    		
    		transparency += interval;
    		if (transparency < maxT)
    			transparency = maxT;    		    		
		}		
		return mask;
	}
}
